

<link rel="stylesheet" href="css/checkbox.css" type="text/css" />
<script type="text/JavaScript">

$(document).ready(function(){
	$(".downloadview").click(function(){
		$(this).next(".detail_dowloadview").slideToggle("slow");
	})						   
})
</script>


	
				<div id="advanced">
				<?php if(empty($id)): ?>
				<form>
				<div id="advancedSearch">
					<table width="95%" border="0" cellspacing="0" cellpadding="0">
					  <tr>
						<td colspan="2"  class="topic_advancedSearch"><img src="images/topic_advancedSearch.gif" /></td>
					  </tr>
					  <tr>
						<td width="180"><br>ชื่อเรื่อง / ชื่อไฟล์ / เนื้อหา</td>
						<td><br><input type="text" name="titlesearch" value="<?=@$_GET['titlesearch'];?>" class="input_box_advancedSearch1"></td>
					  </tr>
					  <tr>
						<td>Tag / Keyword</td>
						<td><input type="text" name="searchtag" value="<?=@$_GET['searchtag'];?>" class="input_box_advancedSearch1"></td>
					  </tr>
					  <tr>
						<td>ประเภทข้อมูล :<br><br></td>
						<td>
							<table border="0" cellspacing="0" cellpadding="0">
								  <tr>
								  	<? foreach($knowledgetype as $item): 
								  	$selected = $item['id']==@$_GET['title'] ? 'selected="selected"' : ""; ?>
									<td width="135"><input type="checkbox" value="<?=$item['id'] ?>" name="checkbox_search" id="checkbox_search"><label> <?=$item['title'] ?></label></td>
								    <? endforeach;?>
								  </tr>
						  </table>
						</td>
					  </tr>
					  <tr>
						<td>กลุ่มข้อมูล :<br><br></td>
						<td>
							<table border="0" cellspacing="0" cellpadding="0">
								  <tr>
				        	<select name="knowledgegroup">
				        		<option value="">-- ไม่ระบุกลุ่มข้อมูล --</option>
				        		<? foreach($knowledgegroup as $item):
								$selected = $item['id']==@$_GET['title'] ? 'selected="selected"' : "";
								echo '<option value="'.$item['id'].'" '.$selected.'>'.$item['title'].'</option>';
								endforeach;
								?>
				        	</select>
								  </tr>
						  </table>
						</td>
					  </tr>
					  <tr>
						<td>หน่วยงานที่กำกับดูแล :<br><br></td>
						<td>
				        	<select name="knowledgetype">
				        		<option value="">-- ไม่ระบุหน่อยงาน --</option>
				        		<? foreach($sectionid as $item):
								$selected = $item['id']==@$_GET['title'] ? 'selected="selected"' : "";
								echo '<option value="'.$item['id'].'" '.$selected.'>'.$item['title'].'</option>';
								endforeach;
								?>
				        	</select>
						</td>
					  </tr>
					  <tr>
						<td>พ.ศ ที่ตีพิมพ์ :<br><br></td>
						<td>
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
							  <tr>
								<td width="200">
									
									<select name="Year" value=""> 
										<option value="">------ไม่ระบุ พ.ศ.------</option>
										<option value="2556">2556</option> 
										<option value="2555">2555</option> 
										<option value="2554">2554</option>
										<option value="2553">2553</option>
										<option value="2552">2552</option>  
										<option value="2551">2551</option>
										<option value="2550">2550</option>
									</select>
							</td>
								<td class="td_day" width="200">วันที่พิมพ์ : <input type="text" name="date1"  class="datepicker" size="10" value=""> <img src="images/icon_calendar.gif" /> </td>
								<td class="td_day" width="200">ถึงวันที่ : <input type="text" name="date2" class="datepicker" size="10" value=""> <img src="images/icon_calendar.gif" />	 </td>
							  </tr>
							</table>

						</td>
					  </tr>
					  <tr>
						<td>&nbsp;</td>
						<td><input type="submit" name="submit" value="ค้นหา" ></td>
					  </tr>
					</table>
					</div>
				</form>
				<? endif?>
				  	  <div id="close"> </div>
						<br>
						<div class="line1"></div><br>
					
					<? if(!empty($dataList)) {?>
					
					<div id="result">
						<?php if(!empty($id)): ?> ข้อมูลความรู้ <?echo $datasection = $this->db->getone("SELECT title FROM tbsection where id =".$id); endif?></br>
						ค้นหาพบทั้งสิ้น <?php echo count($dataList); ?> รายการ 
						<div class="line2"></div>
						
						<?foreach($dataList as $row):?>
						
<?
//$this->db->debug = true;
$date = date("Y-m-d");
$approve = $this->db->getrow('select * from tbknowledgeapproverequest where pid = ? and request_by = ? and (approve_start_date <= curdate() and approve_end_date >= curdate() or (approve_start_date <= curdate() and approve_end_date = "0000-00-00" ))' , array($row['id'], $this->session->userdata('id'))); 
$approve2 = $this->db->getrow('select * from tbknowledgeapproverequest where pid = ? and request_by = ? ' , array($row['id'], $this->session->userdata('id')));
if($row['privatestatus']!=1 or (!empty($approve['approve_by'])) ) :
	?>						
								
								<a href="detail/index/<?=$row['id']?>">
								<p id="title"><?=$row['title']?><br>
											  <?=$row['titleen']?>
								</p>
								</a>		
															    <?
								  echo @$this->db->getone("SELECT description FROM tbknowledge WHERE id=".$row['id']);
								?>		
								<p id="author">
								<br/>	
								<b>ผู้จัดทำ : </b>
									<?php 
										$authors = $this->db->getarray('select tags.tag from tags join tbknowledge_author as kauthor on kauthor.author_id = tags.id  where kauthor.tbknowledge_id = ?', array($row['id']));
										foreach($authors as $k => $author) echo ($k > 0) ? ', '.$author['tag'] : $author['tag'];
									?>
								<br>
								<b>  หน่วยงาน : </b> 
								<?
								  echo @$this->db->getone("SELECT title FROM tbsection WHERE id=".$row['sectionid']);
								?>
								</p>
								<p id="tag">
								
								<b>	Tags : </b>
									<?php 
										$tags = $this->db->getarray('select tags.tag from tags join tbknowledge_tag as ktags on ktags.tag_id = tags.id  where ktags.tbknowledge_id = ?', array($row['id']));
										foreach($tags as $k => $tag) echo ($k > 0) ? ', '.$tag['tag'] : $tag['tag'];
									?>
								</p>
								<br><table border="0" cellspacing="0" cellpadding="0">
										  <tr>
											<td width="60%" >
											<img src="images/icon-calendar.gif" /> <?=db2date($row['publishdate'])?></td>
											<? $date = $row['createdate'];
											   $datetime_arr= explode(" ", $date);
											   
											   $time = $datetime_arr[1];
											  
											?>
											<td><img src="images/icon-clock.gif" />   <?echo $time?></td>
										  </tr>
										</table>
							<br>
						
						
						  <div id="downloadview" class="downloadview"><img src="images/downloadview_reg.png" name="dowloadview" width="130" height="30" border="0" id="dowloadview" /></div>
						  <div id="detail_dowloadview" class="detail_dowloadview" style="display:none;">
						  <table width="97%" border="0" cellspacing="0" cellpadding="20" class="tb_detail_dowloadview">
		
							  <tr class="tr_detail_dowloadview">
								<td class="td_detail_dowloadview" style="padding-left:10px;">รายละเอียดไฟล์</td>
								<td class="td_detail_dowloadview">เปิดด้วยโปรแกรม</td>
								<td class="td_detail_dowloadview">Download Count</td>
								<td class="td_detail_dowloadview">Save</td>
							  </tr>
							<?
							$datafiles = $this->knowledgefiles->where('pid='.$row['id'])->get();
							foreach($datafiles as $items):
							?>
							  <tr class="tr_detail_dowloadview2">
							  	<? 
										$filename = "knowledgefiles/".$items['filename'];
										$size = filesize("$filename"); 
								?>
								<td class="td_2"><a href="#"><?=$items['filename']?> (<?=number_format($size/1024/1024,2). "Mb"?>)</a></td>
								<td><? echo @$this->db->getone("SELECT openprogramname FROM tbfiletype WHERE id=".$items['filetypeid']); ?>	</td>
								<td><?=$items['downloads']?></td>
								<td><a href="detail/counterfiles/<?php echo $items['id']?>"><img src="images/icon-download.png" border="0" /></a></td>
							  </tr>	
							<? endforeach; ?>
						  </table>	  
						  </div>
						  <br/>
						  <div class="line3"> </div>

<? else :?>		

								<p id="title"><?=$row['title']?><br>
											  <?=$row['titleen']?>
								</p>
								<?
								  echo @$this->db->getone("SELECT description FROM tbknowledge WHERE id=".$row['id']);
								?>
								<p id="author">
									<b>ผู้จัดทำ : </b> 
									<?php 
										$authors = $this->db->getarray('select tags.tag from tags join tbknowledge_author as ktags on ktags.author_id = tags.id  where ktags.tbknowledge_id = ?', array($row['id']));
										foreach($authors as $k => $author) echo ($k > 0) ? ', '.$author['tag'] : $author['tag'];
									?>
								<br>
								<b>  หน่วยงาน : </b> 
								<?
								  echo @$this->db->getone("SELECT title FROM tbsection WHERE id=".$row['sectionid']);
								?>
								</p>
								<p id="tag">
								
									<b>Tags : </b> 
									<?php 
										$tags = $this->db->getarray('select tags.tag from tags join tbknowledge_tag as ktags on ktags.tag_id = tags.id  where ktags.tbknowledge_id = ?', array($row['id']));
										foreach($tags as $k => $tag) echo ($k > 0) ? ', '.$tag['tag'] : $tag['tag'];
									?>
								</p>
								<br><table border="0" cellspacing="0" cellpadding="0">
										  <tr>
											<td width="60%" ><img src="images/icon-calendar.gif" /> <?=db2date($row['publishdate'])?></td>
											<? $date = $row['createdate'];
											   $datetime_arr= explode(" ", $date);
											   
											   $time = $datetime_arr[1];
											  
											?>
											<td><img src="images/icon-clock.gif" />   <?echo $time?></td>
										  </tr>
										</table>
							<br>
						
						
											<? if(!empty($approve2['id']) ): ?>
								      			<br/><div align="center">
												<form action="advancedsearch/privatestatus/<?=$row['id']?>" method="post">
										 			<table width="65%" border="0" cellspacing="0" cellpadding="20" class="tb_alert_txt2">
										 				 <tr align="center" class="">
										 						<td class="td_alert_txt2" >กำลังดำเนินการขออนุญาตการเข้าใช้ข้อมูล</td>
										 				 </tr>
										 			
										 			</table>
									 		    </form>	 
												</div><br/>
												<div class="line3"> </div>
											<?php else: ?>
									      	<br/><div align="center">
												<form action="advancedsearch/privatestatus/<?=$row['id']?>" method="post" target="_blank">
										 			<table width="75%" border="0" cellspacing="0" cellpadding="20" class="tb_alert_txt">
										 				 <tr align="center" class="">
										 						<td class="td_alert_txt">ข้อมูลนี้ต้องทำการขออนุญาตการเข้าถึงข้อมูลก่อนถึงจะสามารถดูรายละเอียดข้อมูลได้</td>
										 				 </tr>
										 				 <tr class="">
										 						<td class="" align="center">
										 							<br/><input type="submit" name="submit" value="ขออนุญาติ" class="btn_save" >
										 						</td>
										 				 </tr>
										 			</table>
									 		    </form>	 
												</div><br/>
												<div class="line3"> </div>
						  					<?endif ?>									
						 	      	
								      
 <?endif ?>
				 <? endforeach; ?>
				  
				  </div>
				  <?}?>

				 </div>
				

